import { createStore, applyMiddleware, compose } from "redux";
// import thunk from "redux-thunk"; // 中间件
import reducer from "./reducer";
import createSagaMiddleware from "redux-saga";
import TodoSagas from "./sagas";

const sagaMiddleware = createSagaMiddleware();
// 中间件和 redux-tools同时存在代码
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
  ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
  : compose;

const enhancer = composeEnhancers(applyMiddleware(sagaMiddleware)); // saga 中间件
// applyMiddleware(thunk) // thunk中间件
const store = createStore(reducer, enhancer);

sagaMiddleware.run(TodoSagas);

export default store;
